package com.ztt.service.impl;

import com.ztt.pojo.entity.zttEmployee;
import com.ztt.mapper.EmployeeMapper;
import com.ztt.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public zttEmployee getEmployeeById(zttEmployee EmployeeID) {
        return employeeMapper.getEmployeeById(EmployeeID);
    }

    @Override
    public List<zttEmployee> selectAllEmployee(){
        return employeeMapper.selectAllEmployee();
    };

    @Override
    public void insertEmployee(zttEmployee employee){
        employeeMapper.insertEmployee(employee);
    }

    @Override
    public void updateEmployee(zttEmployee employee){
        String employeeID = employee.getEmployeeID();
        if(employeeID!=null){
            zttEmployee employee1 = employeeMapper.getEmployeeById(employee);
            String employeeName = employee.getEmployeeName();
            if(employeeName!=""){
                employee1.setEmployeeName(employeeName);
            }
            String employeePassword = employee.getEmployeePassword();
            if(employeePassword!=""){
                employee1.setEmployeePassword(employeePassword);
            }
            String employeeLevel = employee.getEmployeeLevel();
            if(employeeLevel!=""){
                employee1.setEmployeeLevel(employeeLevel);
            }
            String employeePhone = employee.getEmployeePhone();
            if(employeePhone!=""){
                employee1.setEmployeePhone(employeePhone);
            }
            int employeeSalary = employee.getEmployeeSalary();
            if(employeeSalary>employee1.getEmployeeSalary()){
                employee1.setEmployeeSalary(employeeSalary);
            }
            String notes = employee.getNotes();
            if(notes!=""){
                employee1.setNotes(notes);
            }
            employeeMapper.updateEmployee(employee1);
        }

    }

    @Override
    public zttEmployee getEmployeeByName(zttEmployee employee){
        return employeeMapper.getEmployeeByName(employee);
    }


    @Override
    public void deleteEmployee(zttEmployee employee){
        employeeMapper.deleteEmployee(employee);
    }

}
